import {ApiResponse, http, ListResponse, SearchKeyQueryParam} from 'slash-admin'


export interface AuthTbRoleResponse {
    id: string,
    roleName: string,
    roleCode: string,
    isDefault: number,
    priorityLevel: number,
    enabled: number,
    allowDel: number,
    createTime: string,
    updateTime: string,
    createUserAccount: string,
    updateUserAccount: string,
}

export interface SelectAuthTbRolePageListQueryParam extends SearchKeyQueryParam {

}
export interface SysTbSecurityObjResponse {
    id:string,
    createTime:string,
    updateTime:string,
    createUserAccount:string,
    updateUserAccount:string,
    securityObjName:string,
    securityObjEntityName:string,
    securityObjTableName:string,
    resourceAppCode:string,
}
export interface SysTbSecurityObjFieldResponse {
    id:string,
    createTime:string,
    updateTime:string,
    createUserAccount:string,
    updateUserAccount:string,
    fkSecurityObjId:string,
    fieldName:string,
    fieldChinese:string,
    fieldConfig:any,
}

/**
 * 分页查询列表
 * @param query
 */
export const selectPageList = (query: SelectAuthTbRolePageListQueryParam): Promise<ListResponse<AuthTbRoleResponse>> => {
    return http.doGet('/AuthApp/AuthTbRole/selectPageList', query)
}
/**
 * 根据ID查询
 * @param id
 */
export const selectById = (id: string | number): Promise<ApiResponse<AuthTbRoleResponse>> => {
    return http.doGet('/AuthApp/AuthTbRole/selectById', {id: id})
}

/**
 * 根据roleCode查询
 * @param roleCode
 */
export const selectByRoleCode = (roleCode: string): Promise<ApiResponse<AuthTbRoleResponse>> => {
    return http.doGet('/AuthApp/AuthTbRole/selectByRoleCode', {roleCode: roleCode})
}
/**
 * 根据roleCode查询
 * @param roleCode
 */
export const selectListByUserId = (userId: string): Promise<ListResponse<AuthTbRoleResponse>> => {
    return http.doGet('/AuthApp/AuthTbRole/selectListByUserId', {userId: userId})
}
/**
 * 新增
 * @param data
 */
export const doSaveEntity = (data: any): Promise<ApiResponse<boolean>> => {
    return http.doPost('/AuthApp/AuthTbRole/save', data)
}
/**
 * 更新资源关系
 * @param data
 */
export const doUpdateRoleRelation = (data: any): Promise<ApiResponse<boolean>> => {
    return http.doPost('/AuthApp/authFkRoleResource/updateRoleRelation', data)
}
/**
 * 实体
 * @param data
 */
export const doUpdateEntity = (data: any): Promise<ApiResponse<boolean>> => {
    return http.doPost('/AuthApp/AuthTbRole/update', data)
}
/**
 * 逻辑删除
 * @param id|ids
 */
export const doLogicDeleteEntity = (ids: Array<string | number> | number | string): Promise<ApiResponse<boolean>> => {
    let data: any = null;
    if (Array.isArray(ids)) {
        data = ids;
    } else {
        data = [ids];
    }
    return http.doPost('/AuthApp/AuthTbRole/logicDelete', data)
}
/**
 * 物理删除
 * @param id|ids
 */
export const doDeleteEntity = (ids: Array<string> | number | string): Promise<ApiResponse<boolean>> => {
    let data: any = null;
    if (Array.isArray(ids)) {
        data = ids;
    } else {
        data = [ids];
    }
    return http.doPost('/AuthApp/AuthTbRole/delete', data)
}

export const selectList = (query: {}): Promise<ListResponse<AuthTbRoleResponse>> => {
    return http.doGet('/AuthApp/AuthTbRole/selectList', query)
}
/**
 * 根据角色编码查询
 * @param query
 */
export const selectResourceIdListByRoleCode = (roleCode: string): Promise<ListResponse<AuthTbRoleResponse>> => {
    return http.doGet('/AuthApp/authFkRoleResource/selectResourceIdListByRoleCode', {roleCode: roleCode})
}
/**
 * 分页查询列表
 * @param query
 */
export const selectSecurityObjTreeList = (query: any): Promise<ListResponse<SysTbSecurityObjResponse>> => {
    return http.doGet('/SysApp/SysTbSecurityObj/selectTreeList', query)
}
/**
 * 分页查询列表
 * @param query
 */
export const selectSecurityObjFieldPageList = (query: any): Promise<ListResponse<SysTbSecurityObjFieldResponse>> => {
    return http.doGet('/SysApp/SysTbSecurityObjField/selectPageList', query)
}
export default {
    selectPageList,
    selectList,
    selectById,
    doDeleteEntity,
    doLogicDeleteEntity,
    doUpdateEntity,
    doSaveEntity,
    selectByRoleCode,
    selectListByUserId,
    doUpdateRoleRelation,
    selectResourceIdListByRoleCode,
    selectSecurityObjTreeList,
    selectSecurityObjFieldPageList
}
